home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Help / ElecCompletions Help < prev    next >
Encoding:
Text File  |  2001-02-02  |  16.2 KB  |  439 lines

  1. ## 
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "ElecCompletions Help"
  6.  #                                    created: 00-05-19 16.44.50 
  7.  #                                last update: 01-02-02 18.55.02 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <vince@santafe.edu>
  10.  #    mail: 317 Paseo de Peralta
  11.  #          Santa Fe, NM 87501, USA
  12.  #     www: <http://www.santafe.edu/~vince/>
  13.  #  
  14.  # Copyright (c) 1997-2000  Vince Darley
  15.  # Some pieces pasted from Alpha-D mailing list responses.
  16.  # ###################################################################
  17.  ##
  18.  
  19.  
  20. The idea with electric completions is to save you key strokes. When you hit
  21. ctrl-tab Alpha tries to expand what you have just typed to give the rest of
  22. what you want (the choice of ctrl-tab can be adjusted in the 
  23. 'Config->Global->Special Keys' dialog).
  24.  
  25. If you want basic help/tutorial information, do the following: when 
  26. you're in a mode for which you want a tutorial on electric completions,
  27. select 'Completions Tutorial' from the 'Mode Prefs' menu.  Follow 
  28. the instructions there.
  29.  
  30. You can modify the following preferences using the 
  31. 'Config->Global->Flags->Electrics' menu item:
  32.  
  33.     • useElectricMenu --- use electric template menu 
  34.     • showElectricsInMenu --- show electric completions in menu 
  35.     • showElectricKeysInMenu --- show electric key bindings in menu
  36.     • modeSpecificElecTab --- use mode-specific electric tab 
  37.     • electricTab --- use electric tab 
  38.     • templateStopColor --- colour of template stops 
  39.     • listPickIfMultExpds --- similarly for expansions 
  40.     • ElectricFillers --- The format of the template stops:
  41.           0 = just use bullets
  42.           1 = use bullets but signal the name in the status window
  43.           2 = insert names into the window with the bullets
  44.           3 = insert names and highlight into the window with the bullets
  45.     • maxTemplateNesting--- level of nesting we allow before clearing 
  46.  
  47. The electric menu contains a 'Templates' sub-menu, which contains global 
  48. templates stored in the variable 'univ::MenuTemplates', and mode-specific
  49. templates stored in variables ${mode}Templates.  The format of these 
  50. variables is a list of names, which correspond to procedures when prepended 
  51. with 'file::'.  You can add new items by using the menu item.
  52.  
  53.           Templates
  54.  
  55. Many of the routines in Vince's Additions allow you to insert templates for 
  56. 'for' loops, '\begin...\end environments', file headers, function comments, 
  57. and even entire documents.  This section details the features of Vince's 
  58. Additions which allow you to do that.  Here's an example of a 'for' template
  59. in C++ mode (created just by typing 'for<ctrl-Tab>'):
  60.  
  61.     for (•<init>;•<test>;•<increment>){
  62.         •<loop body>
  63.     }
  64.     •
  65.  
  66. Once a template has been inserted, it will often contain a number of 
  67. 'place-markers' or 'template-stops' at each of which you will most likely 
  68. wish to enter some text/code.  You can jump backwards and forwards amongst 
  69. these stops using a set of key bindings.  You have a choice between two 
  70. basic sets (you select using the 'Electric Bindings' dialog):
  71.  
  72. Function                Default binding             Alternative binding
  73.  
  74. Expand                  command-space               command-space
  75. Next stop or indent     tab                         no binding
  76. nth Stop                no binding                  control-tab
  77. Complete or Tab         no binding                  tab
  78. Next stop               no binding                  control-j
  79. Clear all stops         shift-control-tab           shift-control-tab
  80. Complete                control-tab                 no binding
  81. Real tab                option-tab                  option-tab
  82. Prev stop               shift-tab                   shift-control-j
  83.  
  84. Furthermore you can redefine any of these bindings using that same
  85. dialog.
  86.  
  87. You have a choice between four different formats for the visual appearance 
  88. of the template-stops.  They are usually signified by a bullet '•', but 
  89. more elaborate methods are supported.  These templates may be nested 
  90. without any extra effort on your part.  Most of this code is contained in 
  91. the file "betterTemplates.tcl", although all the bindings and initialisation 
  92. are in "elecBindings.tcl".
  93.  
  94. Look at the new 'electric' menu for a list of these bindings, together 
  95. with some other functions.
  96.  
  97. ================================================================================
  98.  
  99.           Completions
  100.  
  101. I've now written a unified collection of procedures to address command 
  102. completion, code indentation, electric-code generation, word completion and 
  103. related facilities (incorporating my old TeX-reference completion for 
  104. example). 
  105.  
  106. Here's a typical example from TeX mode, I type:
  107.  
  108.     for an explanation of this phenomenon,
  109.     please refer to Fig<ctrl-Tab>
  110.     
  111. The <ctrl-Tab> signifies that Vince's Additions should try to complete the 
  112. currently typed text.  In this case the completion is:
  113.  
  114.     for an explanation of this phenomenon,
  115.     please refer to Figure~\ref{fig-
  116.     
  117. If I hit <ctrl-Tab> again, Vince's Additions tries to search for TeX 
  118. '\labels' which begin with 'fig-' to insert the first such label
  119. it finds into the text:
  120.  
  121.     for an explanation of this phenomenon,
  122.     please refer to Figure~\ref{fig-heat-vs-time}
  123.     
  124. If this is the wrong one, I can keep hitting <ctrl-Tab> until I reach the 
  125. correct completion:
  126.  
  127.     for an explanation of this phenomenon,
  128.     please refer to Figure~\ref{fig-explanation}
  129.     
  130. Here's an example from C/C++ modes. I type 'for<ctrl-Tab>' and get:
  131.  
  132.     for (;•;•){
  133.         •
  134.     }
  135.  
  136. This works at any current level of indentation, and the bullet marks '•' 
  137. are placemarkers.  You can just press 'Tab' (without 'ctrl') to jump from 
  138. one to the next.
  139.  
  140. These facilities are activated as follows:
  141.  
  142. •    Tab --- plain - either 'indent' or 'next template mark'
  143.             ctrl   - complete the current text.
  144.             opt   - insert a real tab.
  145.                         
  146. So, pressing Tab by default will _not_ necessarily insert a tab, rather it 
  147. will indent the current line of code to the correct indentation level to 
  148. match the code around it.  
  149.  
  150.             Types of completion
  151.  
  152.  
  153. Control-Tab has a number of different meanings, which will be explained 
  154. below.  Completions are listed in order of precedence.
  155.  
  156.               User completion: 
  157.  
  158. all entries defined in the array 'userCompletions' are checked and inserted 
  159. if appropriate.  This is useful to make 'vmd' turn into 'Vince Darley', or 
  160. 'www' into my home-page url, or ...
  161.     
  162. User completions are active in all modes, and take precedence over all 
  163. other completion types.
  164.  
  165.               Context sensitive completion: 
  166.  
  167. Context sensitive completions are mode dependent.  In some modes you 
  168. can tell relatively easily from the context whether a particular 
  169. 'word' is a variable or procedure name or...  If different completion
  170. procedures are useful for different types of word, then they are 
  171. checked next.  For instance, in Tcl mode, a word beginning with '$',
  172. or preceded by 'set' or 'global' is a variable name.  It should 
  173. therefore be completed preferentially as a variable, rather than
  174. being expanded as a command.  E.g. $str should normally not be
  175. expanded to '$string ...' since it's clearly not the command 'string' 
  176. that the user is trying to type.  
  177.  
  178.               Command completion: 
  179.  
  180. For instance: type 'str<ctrl-tab>' and it is completed to 'string' (in Tcl 
  181. mode).  If there are multiple possibilities then the longest unique prefix 
  182. is inserted.
  183.     
  184. The available completions are mode dependent, and stored as a large string 
  185. in the variable ${mode}cmds.  They must be stored alphabetically, and
  186. be separated by whitespace.  THERE IS NO LONGER A NEED TO BEGIN AND
  187. END THE LIST WITH WHITESPACE.
  188.  
  189. Here is the default value for Tcl mode:
  190.  
  191.     set Tclcmds { append array catch close concat continue elseif error
  192.     for foreach format lindex lsearch lsort regexp regsub
  193.     rename return string switch while }
  194.  
  195.               Ensemble completion: 
  196.  
  197. type 'string co<ctrl-Tab>' and this is both completed to 'string compare' and 
  198. an electric template is inserted for the arguments of this two part 
  199. command.  Useful for any case in which the word before last is the command, 
  200. and the word just before is part of a refinement of that command, in any 
  201. situation for which a number of further arguments will be filled in.
  202.     
  203.               Electric code template generation: 
  204.  
  205. type 'for<ctrl-tab>' and a complete template for code is generated (example 
  206. for C mode):
  207.     
  208.     for (;•;•){
  209.         •
  210.     }
  211.  
  212. You can move from one template mark '•' to the next with, plain 'Tab' - 
  213. I automatically sense whether a template insertion is in progress or
  214. not and interpret tab accordingly.
  215.  
  216. These are again mode dependent. Each is stored individually as an element 
  217. of the array ${mode}electrics, so, for instance the above electric code is 
  218. generated by:
  219.  
  220.     set Celectrics(for) " (••;••;••)\{\n\t••\n\}\n••"
  221.  
  222. Note how the bullets are double in the definition.  You can actually place 
  223. an explanatory bit of text between pairs of bullets.  This is then used as 
  224. a hint to the user:
  225.  
  226.     set Celectrics(for) " (•start•;•test•;•increment•)\{\n\t•body•\n\}\n••"
  227.  
  228.               Class name completion: 
  229.  
  230. In C++ mode, when entering a class definition, the class name occurs 
  231. multiple times.  To save entering all of these, this completion will
  232. fill them all in for you.  It works like this: type 'class<ctrl-tab>'
  233.  
  234.     class •<object name> : public •<parent> {
  235.       public:
  236.         •<object name>(•<args>);
  237.         ~•<object name>(void);
  238.     
  239.     };
  240.     •
  241.  
  242. Now type the class name, say 'toaster', followed by <ctrl-tab>.  This
  243. will result in:
  244.  
  245.     class toaster : public •<parent> {
  246.       public:
  247.         toaster(•<args>);
  248.         ~toaster(void);
  249.     
  250.     };
  251.     •
  252.  
  253. i.e. each occurrence of the electric stop 'object name' has been 
  254. filled in correctly.  This feature may be easily extended to more
  255. complex examples.
  256.  
  257.               TeX reference completion: 
  258.  
  259. type '\ref<ctrl-Tab>' and the command is automatically completed with the 
  260. name of a nearby \label{}.  Repeated <ctrl-Tab> keypresses will cycle 
  261. through all \label's.  Further, these commands chain together, so typing 
  262. '\eqr<ctrl-Tab>' will complete the \eqref and continue to fill in a nearby 
  263. label!
  264.  
  265. These were explained above.  Note that the reference completions can be 
  266. instigated by command completion on, 'Fig' 'Chap' 'Eq.'  'Sec', ...  which 
  267. insert the standard label prefix 'fig:' 'chap:' 'eq:' 'sec:' as 
  268. appropriate.  If you complete with no prefix, then any label will match; if 
  269. you have a prefix then only those which match will be suggested.
  270.  
  271.               TeX citation completion.  
  272.  
  273. Type '\cite{Darley19<ctrl-Tab>' and the command is completed with a matching 
  274. citation entry from one of your '.bib' database files.  If there are 
  275. multiple possibilities, then you are prompted with a list from which to 
  276. choose.  (Note: if you find the selection box a bit narrow, it is possible
  277. to edit Alpha using ResEdit to increase its size).  Depending upon the
  278. value of a TeX flag, the list can include the titles of each choice,
  279. making it more obvious to you which is correct.
  280.  
  281.               TeX environment completion: 
  282.  
  283. \begin{} \end{} pairs with synchronisation of the parameter, and template 
  284. generation of the body.
  285.  
  286. You can complete '\begin<ctrl-Tab>' followed by 'equ<ctrl-Tab>' to the
  287. following:
  288.  
  289.     \begin{equation}
  290.         •
  291.         \label{eq:•}
  292.     \end{equation}
  293.     •
  294.  
  295. You have a choice between the double-completion, as above, or just typing
  296. '\begin{equation}<ctrl-Tab>' which will do the job in one go.
  297.  
  298. Similar things work for 'itemize' 'enumerate' etc.  Of particular use
  299. are the completions for 'figure' environments, from which you can enter
  300. ordinary figures, floating figures, and a large number of sub-figure 
  301. configurations (2 figures side-by-side, a block of 4,...).  For instance,
  302. a handful of key-presses will give you this:
  303.  
  304.     \begin{figure}
  305.         \centering
  306.         \subfigure[•“subfig caption”]{\label{fig:•}%
  307.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  308.         \subfigure[•“subfig caption”]{\label{fig:•}%
  309.             \includegraphics[width=\figstwo]{•“graphics file”}}\\
  310.         \subfigure[•“subfig caption”]{\label{fig:•}%
  311.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  312.         \subfigure[•“subfig caption”]{\label{fig:•}%
  313.             \includegraphics[width=\figstwo]{•“graphics file”}}%
  314.         \caption•“[short caption for t.o.f.]”{•“caption”}
  315.         \label{fig:•}
  316.     \end{figure}
  317.     •
  318.  
  319. For these to work, you must use the correct LaTeX packages (graphics, 
  320. floatingfigure or subfigure as appropriate, although the code will 
  321. automatically insert the correct 'usepackage' specifications for you if 
  322. desired), and you may need the following definitions in your LaTeX 
  323. preamble:
  324.  
  325.     \newlength{\goodspace}
  326.     \newlength{\goodspacethree}
  327.     \newlength{\goodspacefour}
  328.     \newlength{\figstwo}
  329.     \newlength{\figsthree}
  330.     \newlength{\figsfour}
  331.     
  332.     \setlength{\goodspace}{\subfigtopskip+\subfigbottomskip}
  333.     \setlength{\goodspacethree}{\goodspace}
  334.     \setlength{\goodspacefour}{\goodspace*\real{0.6}}
  335.     
  336.     \newcommand{\goodgap}{\hspace{\goodspace}}
  337.     \newcommand{\goodgaptwo}{\goodgap}
  338.     \newcommand{\goodgapthree}{\hspace{\goodspacethree}}
  339.     \newcommand{\goodgapfour}{\hspace{\goodspacefour}}
  340.     
  341.     \setlength{\figstwo}{(\linewidth-\goodspace)/2-1pt}
  342.     \setlength{\figsthree}{(\linewidth-\goodspace *2)/3-1pt}
  343.     \setlength{\figsfour}{(\linewidth-\goodspace *\real{1.8})/4-1pt}
  344.  
  345. These allow good alignment and spacing for most subfigure combinations
  346. without the need for manual intervention.  
  347.  
  348. Some environments can contain an arbitrary number of items.  In this case, 
  349. hitting 'shift-option-i' will add an item.  Here we turn this:
  350.  
  351.     \begin{description}
  352.         \item[First one] here's the description
  353.         
  354.         \item[•“name”] •“description”
  355.         
  356.     \end{description}
  357.     •
  358.  
  359. into:
  360.  
  361.     \begin{description}
  362.         \item[First one] here's the description
  363.         \item[•] •
  364.         
  365.         \item[•“name”] •“description”
  366.         
  367.     \end{description}
  368.     •
  369.  
  370. Similar entries work correctly for itemised, enumerated, aligned,... 
  371. environments.
  372.  
  373.               File-name completion:
  374.  
  375. Useful for Shel mode, this allows you to type a partial directory or 
  376. filename and hit ctrl-Tab to have it extended as much as possible.
  377.  
  378.               Tcl Variable Completion:
  379.  
  380. Tcl variables are often referenced with '$var' or just 'var' or '${var}'.  
  381. You can complete between any of these types.  A local search for a match is 
  382. done and the closest match inserted.  Again you can cycle through other 
  383. matches with <ctrl-Tab>
  384.  
  385.               Word Completion: 
  386.  
  387. if none of the above succeeded then the current word is completed to copy 
  388. nearby words (variable names) in the file.  Again, repeated presses will 
  389. cycle through other possibilities.
  390.  
  391. In any form of text in any mode, if no mode-specific completion matches, 
  392. then any local word can match, complete and be cycled through as usual.
  393.  
  394.             Template insertion
  395.  
  396. You'll notice in a lot of the above examples that bullets '•' are inserted
  397. into the text. In fact the user has a choice of four different levels of
  398. interaction with the template insertion procedures. You can change this
  399. using the universal preferences dialog (in the config menu). You can move
  400. from one insertion point to the next using the 'tab' key; move backwards
  401. with 'shift-tab'. If you don't like these key bindings, an alternative set
  402. is available by a change in the universal preferences. You can also choose
  403. the colour of the inserted bullets/prompts.
  404.  
  405.             The Electric Menu
  406.  
  407. By default all items in the ${mode}electrics array are inserted into a new 
  408. menu.  This allows you to insert them, and get a feel for a small number 
  409. of the completions which exist.  Also at the bottom of the menu are items 
  410. for each of the standard key bindings these routines use, to help you to 
  411. remember them.
  412.  
  413.             Completion feedback
  414.  
  415. Help me to help you!
  416.  
  417. Completions for some common items just don't currently exist.  So if you 
  418. try to complete something and it doesn't work, why not write a completion 
  419. for it?  Once you have assembled a few, mail them to me (preferably 
  420. binhex'd, since bullets '•' don't travel well by ASCII mail).  I'd
  421. particularly like completions for other modes.
  422.  
  423.             Speed
  424.  
  425. Alpha has some limitations which means some aspects of Vince's Additions
  426. are a little bit slow (on low-end machines, at least).
  427.  
  428. Two things you can do to alleviate this: first, in modes for which Tab (or 
  429. ctrl-j under the alternative bindings) ALWAYS means to go the next template 
  430. stop and never means to indent the current line, define a new mode variable 
  431. 'tabNeverIndents' by adding the following line to your "prefs.tcl":
  432.   
  433.     newPref f tabNeverIndents 1 MODE
  434.  
  435. where 'MODE' is 'TeX', 'Java', 'HTML' or whatever.  You'll need to add one
  436. such line for each relevant mode.
  437.   
  438. ================================================================================
  439.